{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check if Word Equals Summation of Two Words"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isSumEqual"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #检查某单词是否等于两单词之和"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>字母的 <strong>字母值</strong> 取决于字母在字母表中的位置，<strong>从 0 开始</strong> 计数。即，<code>'a' -&gt; 0</code>、<code>'b' -&gt; 1</code>、<code>'c' -&gt; 2</code>，以此类推。</p>\n",
    "\n",
    "<p>对某个由小写字母组成的字符串 <code>s</code> 而言，其 <strong>数值</strong> 就等于将 <code>s</code> 中每个字母的 <strong>字母值</strong> 按顺序 <strong>连接</strong> 并 <strong>转换</strong> 成对应整数。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如，<code>s = \"acb\"</code> ，依次连接每个字母的字母值可以得到 <code>\"021\"</code> ，转换为整数得到 <code>21</code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>给你三个字符串 <code>firstWord</code>、<code>secondWord</code> 和 <code>targetWord</code> ，每个字符串都由从 <code>'a'</code> 到 <code>'j'</code> （<strong>含 </strong><code>'a'</code> 和 <code>'j'</code><strong> </strong>）的小写英文字母组成。</p>\n",
    "\n",
    "<p>如果 <code>firstWord</code><em> </em>和<em> </em><code>secondWord</code> 的 <strong>数值之和</strong> 等于<em> </em><code>targetWord</code><em> </em>的数值，返回 <code>true</code> ；否则，返回<em> </em><code>false</code><em> </em>。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>firstWord = \"acb\", secondWord = \"cba\", targetWord = \"cdb\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>\n",
    "firstWord 的数值为 \"acb\" -&gt; \"021\" -&gt; 21\n",
    "secondWord 的数值为 \"cba\" -&gt; \"210\" -&gt; 210\n",
    "targetWord 的数值为 \"cdb\" -&gt; \"231\" -&gt; 231\n",
    "由于 21 + 210 == 231 ，返回 true\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aab\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>\n",
    "firstWord 的数值为 \"aaa\" -&gt; \"000\" -&gt; 0\n",
    "secondWord 的数值为 \"a\" -&gt; \"0\" -&gt; 0\n",
    "targetWord 的数值为 \"aab\" -&gt; \"001\" -&gt; 1\n",
    "由于 0 + 0 != 1 ，返回 false</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aaaa\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>\n",
    "firstWord 的数值为 \"aaa\" -&gt; \"000\" -&gt; 0\n",
    "secondWord 的数值为 \"a\" -&gt; \"0\" -&gt; 0\n",
    "targetWord 的数值为 \"aaaa\" -&gt; \"0000\" -&gt; 0\n",
    "由于 0 + 0 == 0 ，返回 true\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= firstWord.length, </code><code>secondWord.length, </code><code>targetWord.length &lt;= 8</code></li>\n",
    "\t<li><code>firstWord</code>、<code>secondWord</code> 和 <code>targetWord</code> 仅由从 <code>'a'</code> 到 <code>'j'</code> （<strong>含 </strong><code>'a'</code> 和 <code>'j'</code><strong> </strong>）的小写英文字母组成<strong>。</strong></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-if-word-equals-summation-of-two-words](https://leetcode.cn/problems/check-if-word-equals-summation-of-two-words/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-if-word-equals-summation-of-two-words](https://leetcode.cn/problems/check-if-word-equals-summation-of-two-words/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"acb\"\\n\"cba\"\\n\"cdb\"', '\"aaa\"\\n\"a\"\\n\"aab\"', '\"aaa\"\\n\"a\"\\n\"aaaa\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        return int(''.join(str(ord(i)-97) for i in firstWord)) + int(''.join(str(ord(i)-97) for i in secondWord)) == int(''.join(str(ord(i)-97) for i in targetWord))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def change(s):\n",
    "            su=0\n",
    "            for i in s:\n",
    "                su=su*10+ord(i)-97\n",
    "            return su\n",
    "        return change(firstWord)+change(secondWord)==change(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        lst = ['a','b','c','d','e','f','g','h','i','j','k','i','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n",
    "        sum_1 = ''\n",
    "        sum_2 =''\n",
    "        sum_tar = ''\n",
    "        for i in firstWord:\n",
    "            sum_1+= str(lst.index(i))\n",
    "        for i in secondWord:\n",
    "            sum_2+= str(lst.index(i))\n",
    "        for i in targetWord:\n",
    "            sum_tar += str(lst.index(i))\n",
    "        return int(sum_1)+int(sum_2) ==int(sum_tar) \n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def f(s):\n",
    "            return int(''.join([str(ord(x) - ord('a')) for x in s]))\n",
    "        \n",
    "        return f(firstWord) + f(secondWord) == f(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        firstnums = int(\"\".join(map(str,[ord(i)-97 for i in list(firstWord)])))\n",
    "        secondnums =int(\"\".join(map(str,[ord(i)-97 for i in list(secondWord)])))\n",
    "        targetnums =int(\"\".join(map(str,[ord(i)-97 for i in list(targetWord)])))\n",
    "        return (firstnums + secondnums == targetnums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        zd = dict(zip(\"abcdefghij\", \"0123456789\"))\n",
    "        return int(\"\".join(zd[i] for i in firstWord))+int(\"\".join(zd[i] for i in secondWord)) == int(\"\".join(zd[i] for i in targetWord))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def F(s):\n",
    "            ret = 0\n",
    "            for x in s:\n",
    "                ret = ret * 10 + ord(x) - ord('a')\n",
    "            return ret\n",
    "        return F(firstWord) + F(secondWord) == F(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        f = s = t = ''\n",
    "        for i in firstWord:\n",
    "            f += str(ord(i) - ord('a'))\n",
    "        for i in secondWord:\n",
    "            s += str(ord(i) - ord('a'))\n",
    "        for i in targetWord:\n",
    "            t += str(ord(i) - ord('a'))\n",
    "        return int(f) + int(s) == int(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        return (f := lambda word: int(''.join([str(ord(w) - ord('a')) for w in word]))) and f(firstWord) + f(secondWord) == f(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "\n",
    "\n",
    "        def decode(word):\n",
    "            res = 0\n",
    "            for c in word:\n",
    "                a = ord(c) - ord('a')\n",
    "                res = res * 10 + a\n",
    "            return res\n",
    "\n",
    "\n",
    "        return decode(firstWord) + decode(secondWord) == decode(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def decode(word):\n",
    "            res = 0\n",
    "            for i in word:\n",
    "                res *=10\n",
    "                res += ord(i)-ord(\"a\")\n",
    "            return res\n",
    "        return decode(firstWord)+decode(secondWord) == decode(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        s = string.ascii_lowercase\n",
    "        for i in range(len(s)):\n",
    "            firstWord = firstWord.replace(s[i], str(i))\n",
    "            secondWord = secondWord.replace(s[i], str(i))\n",
    "            targetWord = targetWord.replace(s[i], str(i))\n",
    "\n",
    "        return int(firstWord) + int(secondWord) == int(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def getnum(s):\n",
    "            n = 0\n",
    "            for c in s:\n",
    "                n = n * 10 + ord(c) - 97\n",
    "            return n\n",
    "\n",
    "        return getnum(firstWord) + getnum(secondWord) == getnum(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        # 字母  --> 数字转换函数\n",
    "        # def tranformer(s):\n",
    "        #     tm = \"\"\n",
    "        #     for ch in s:\n",
    "        #         tm += str(ord(ch)-97)\n",
    "        #     return int(tm)\n",
    "\n",
    "        # return tranformer(firstWord)+tranformer(secondWord) == tranformer(targetWord)\n",
    "\n",
    "\n",
    "        # 直接计算\n",
    "        def get_num(s):\n",
    "            total = 0\n",
    "            for i in s:\n",
    "                total = total * 10 + (ord(i) - 97) \n",
    "            return total\n",
    "\n",
    "        return get_num(firstWord) + get_num(secondWord) == get_num(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def getNum(word):\n",
    "            res = \"\"\n",
    "            for ch in word:\n",
    "                res += str( ord(ch) - ord('a') )\n",
    "            res = res.lstrip('0')\n",
    "            return eval(res) if res else 0\n",
    "            # return eval(res.lstrip('0'))\n",
    "\n",
    "        firstNum = getNum(firstWord)\n",
    "        secondNum = getNum(secondWord)\n",
    "        targetNum = getNum(targetWord)\n",
    "        return firstNum + secondNum == targetNum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def trans_2_digit(s):\n",
    "            num = 0\n",
    "            for i in s:\n",
    "                num = num * 10 + ord(i)-97\n",
    "            return num\n",
    "\n",
    "        first_num = trans_2_digit(firstWord)\n",
    "        second_num = trans_2_digit(secondWord)\n",
    "        target_num = trans_2_digit(targetWord)\n",
    "\n",
    "        if first_num+second_num == target_num:\n",
    "            return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        x1 = \"\"\n",
    "        x2 = \"\"\n",
    "        x3 = \"\"\n",
    "        # for i in range (len(firstWord)):\n",
    "        #     x1 += str(ord(firstWord[i]) - 97)\n",
    "        # for i in range (len(secondWord)):\n",
    "        #     x2 += str(ord(secondWord[i]) - 97)\n",
    "        # for i in range (len(targetWord)):\n",
    "        #     x3 += str(ord(targetWord[i]) - 97)\n",
    "        # return int(x1) + int(x2) == int(x3)\n",
    "        l1 = {\"a\":0, \"b\":1, \"c\":2, \"d\":3, \"e\":4, \"f\":5, \"g\":6, \"h\":7, \"i\":8, \"j\":9}\n",
    "        for i in range (len(firstWord)):\n",
    "            x1 += str(l1[firstWord[i]])\n",
    "        for i in range (len(secondWord)):\n",
    "            x2 += str(l1[secondWord[i]])\n",
    "        for i in range (len(targetWord)):\n",
    "            x3 += str(l1[targetWord[i]])\n",
    "        return int(x1) + int(x2) == int(x3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        if StringValue(firstWord)+StringValue(secondWord)==StringValue(targetWord):\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "def StringValue(s):\n",
    "    sum=0\n",
    "    for i in range(len(s)):\n",
    "        c=s[-i-1]\n",
    "        sum+=(ord(c)-97)*10**i\n",
    "    return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        letter = list('abcdefghijklmnopqrstuvwxyz')\n",
    "        firstvalue,secondvalue,targetvalue ='','',''\n",
    "        for v in firstWord:\n",
    "            firstvalue=firstvalue+str(letter.index(v))\n",
    "        for k in secondWord:\n",
    "            secondvalue = secondvalue+str(letter.index(k))\n",
    "        for t in targetWord:\n",
    "            targetvalue = targetvalue+str(letter.index(t))\n",
    "        if (int(secondvalue)+int(firstvalue))==int(targetvalue):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        sum1,sum2,sum3=0,0,0\n",
    "        for i in firstWord:\n",
    "            sum1=sum1*10+ord(i)-ord('a')\n",
    "        for i in secondWord:\n",
    "            sum2=sum2*10+ord(i)-ord('a')\n",
    "        for i in targetWord:\n",
    "            sum3=sum3*10+ord(i)-ord('a')\n",
    "        return sum1+sum2==sum3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def word2num(s: str) -> int:\n",
    "            ans = 0\n",
    "            for i in s:\n",
    "                ans *= 10\n",
    "                ans += ord(i) - ord('a')\n",
    "            return ans\n",
    "        return word2num(firstWord) + word2num(secondWord) == word2num(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        s=''\n",
    "        t=''\n",
    "        x=''\n",
    "        for i in firstWord:\n",
    "            s+=str(ord(i)-97)\n",
    "        for j in secondWord:\n",
    "            t+=str(ord(j)-97)\n",
    "        for a in targetWord:\n",
    "            x+=str(ord(a)-97)\n",
    "        return int(s)+int(t)==int(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord:str):\n",
    "        dic={'a': '0', 'b': '1', 'c': '2', 'd': '3', 'e': '4', 'f': '5', 'g': '6', 'h': '7', 'i': '8', 'j': '9'}\n",
    "        s1=''\n",
    "        s2=''\n",
    "        s3=''\n",
    "        for i in firstWord:\n",
    "            s1+=dic[i]\n",
    "        for t in secondWord:\n",
    "            s2+=dic[t]\n",
    "        for g in targetWord:\n",
    "            s3+=dic[g]\n",
    "        if int(s1)+int(s2)==int(s3):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    import string\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        a = {v: str(i) for i, v in enumerate(list(string.ascii_lowercase[0:10]))}\n",
    "        b = ''\n",
    "        for j in firstWord:\n",
    "            b = b + a[j]\n",
    "        c = ''\n",
    "        for k in secondWord:\n",
    "            c = c + a[k]\n",
    "        d = ''\n",
    "        for n in targetWord:\n",
    "            d = d + a[n]\n",
    "        return int(b) + int(c) == int(d)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def zhuanhuan(s):\n",
    "            s1 = \"\"\n",
    "            for i in s:\n",
    "                s1 = s1+str(ord(i)-ord('a'))\n",
    "            return int(s1)\n",
    "        if zhuanhuan(firstWord)+zhuanhuan(secondWord)==zhuanhuan(targetWord):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def fun(x):\n",
    "            res = ''\n",
    "            for i in x:\n",
    "                res += str(ord(i)-97)\n",
    "            return int(res)\n",
    "        return fun(firstWord) + fun(secondWord) == fun(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "#         a,b,c=0,0,0\n",
    "#         for ch in firstWord:\n",
    "#             a=a*10+(ord(ch)-ord(\"a\"))\n",
    "#         for ch in secondWord:\n",
    "#             b=b*10+(ord(ch)-ord(\"a\"))\n",
    "#         for ch in targetWord:\n",
    "#             c=c*10+(ord(ch)-ord(\"a\"))\n",
    "#         return a+b==c\n",
    "        \n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def decode(word: str) -> int:\n",
    "            res = 0\n",
    "            for ch in word:\n",
    "                res *= 10\n",
    "                res += ord(ch) - ord('a')\n",
    "            return res\n",
    "        \n",
    "        return decode(firstWord) + decode(secondWord) == decode(targetWord)\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def decode(word:str)->str:\n",
    "            res = 0\n",
    "            for ch in word:\n",
    "                res *= 10\n",
    "                res += ord(ch)-ord('a')\n",
    "            return res\n",
    "        return decode(firstWord) + decode(secondWord) == decode(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def alpha2int(s):\n",
    "            temp = 0\n",
    "            x = 1\n",
    "            for i in s[::-1]:\n",
    "                temp += (ord(i) - 97) * x\n",
    "                x *= 10\n",
    "            return temp\n",
    "        return alpha2int(firstWord) + alpha2int(secondWord) == alpha2int(targetWord)\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "            def get_num(s):\n",
    "\n",
    "                total = 0\n",
    "\n",
    "                for i in s:\n",
    "\n",
    "                    total = total * 10 + (ord(i) - 97) \n",
    "\n",
    "                return total\n",
    "\n",
    "\n",
    "\n",
    "            return get_num(firstWord) + get_num(secondWord) == get_num(targetWord)\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        a,b,c=0,0,0\n",
    "        for ch in firstWord:\n",
    "            a=a*10+(ord(ch)-ord(\"a\"))\n",
    "        for ch in secondWord:\n",
    "            b=b*10+(ord(ch)-ord(\"a\"))\n",
    "        for ch in targetWord:\n",
    "            c=c*10+(ord(ch)-ord(\"a\"))\n",
    "        return a+b==c\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        x1 = \"\"\n",
    "        x2 = \"\"\n",
    "        x3 = \"\"\n",
    "        # for i in range (len(firstWord)):\n",
    "        #     x1 += str(ord(firstWord[i]) - 97)\n",
    "        # for i in range (len(secondWord)):\n",
    "        #     x2 += str(ord(secondWord[i]) - 97)\n",
    "        # for i in range (len(targetWord)):\n",
    "        #     x3 += str(ord(targetWord[i]) - 97)\n",
    "        # return int(x1) + int(x2) == int(x3)\n",
    "        l1 = {\"a\":0, \"b\":1, \"c\":2, \"d\":3, \"e\":4, \"f\":5, \"g\":6, \"h\":7, \"i\":8, \"j\":9}\n",
    "        for i in range (len(firstWord)):\n",
    "            x1 += str(l1[firstWord[i]])\n",
    "        for i in range (len(secondWord)):\n",
    "            x2 += str(l1[secondWord[i]])\n",
    "        for i in range (len(targetWord)):\n",
    "            x3 += str(l1[targetWord[i]])\n",
    "        return int(x1) + int(x2) == int(x3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        x1 = 0\n",
    "        x2 = 0\n",
    "        x3 = 0\n",
    "        for i in range (len(firstWord)):\n",
    "            x1 += (ord(firstWord[i]) - 97) * 10 ** (len(firstWord) - i)\n",
    "        for i in range (len(secondWord)):\n",
    "            x2 += (ord(secondWord[i]) - 97) * 10 ** (len(secondWord) - i) \n",
    "        for i in range (len(targetWord)):\n",
    "            x3 += (ord(targetWord[i]) - 97) * 10 ** (len(targetWord) - i) \n",
    "        return x1 + x2 == x3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def decode(word: str) -> int:\n",
    "            res = 0\n",
    "            for ch in word:\n",
    "                res *= 10\n",
    "                res += ord(ch) - ord('a')\n",
    "            return res\n",
    "        \n",
    "        return decode(firstWord) + decode(secondWord) == decode(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def value(string: str) -> int:\n",
    "            ans = 0\n",
    "            for ch in string:\n",
    "                ans = ans * 10 + ord(ch) - ord('a')\n",
    "            return ans\n",
    "        \n",
    "        return value(firstWord) + value(secondWord) == value(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        x1 = \"\"\n",
    "        x2 = \"\"\n",
    "        x3 = \"\"\n",
    "        for i in range (len(firstWord)):\n",
    "            x1 += str(ord(firstWord[i]) - 97)\n",
    "        for i in range (len(secondWord)):\n",
    "            x2 += str(ord(secondWord[i]) - 97)\n",
    "        for i in range (len(targetWord)):\n",
    "            x3 += str(ord(targetWord[i]) - 97)\n",
    "        return int(x1) + int(x2) == int(x3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def get_num(s):\n",
    "            total = 0\n",
    "            for i in s:\n",
    "                total = total * 10 + (ord(i) - 97) \n",
    "            return total\n",
    "\n",
    "        return get_num(firstWord) + get_num(secondWord) == get_num(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        x1 = 0\n",
    "        x2 = 0\n",
    "        x3 = 0\n",
    "        for i in range (len(firstWord)):\n",
    "            x1 += (ord(firstWord[i]) - 97) * 10 ** (len(firstWord) - i)\n",
    "        for i in range (len(secondWord)):\n",
    "            x2 += (ord(secondWord[i]) - 97) * 10 ** (len(secondWord) - i) \n",
    "        for i in range (len(targetWord)):\n",
    "            x3 += (ord(targetWord[i]) - 97) * 10 ** (len(targetWord) - i) \n",
    "        return x1 + x2 == x3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        f,s,t_ = '','',''\n",
    "        for i in range(len(firstWord)):\n",
    "            t = ord(firstWord[i]) - ord('a')\n",
    "            f += str(t)\n",
    "        for i in range(len(secondWord)):\n",
    "            t = ord(secondWord[i]) - ord('a')\n",
    "            s += str(t)\n",
    "        for i in range(len(targetWord)):\n",
    "            t = ord(targetWord[i]) - ord('a')\n",
    "            t_ += str(t)\n",
    "        if int(f) + int(s) == int(t_):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        x1 = \"\"\n",
    "        x2 = \"\"\n",
    "        x3 = \"\"\n",
    "        for i in range (len(firstWord)):\n",
    "            x1 += str(ord(firstWord[i]) - 97)\n",
    "        for i in range (len(secondWord)):\n",
    "            x2 += str(ord(secondWord[i]) - 97)\n",
    "        for i in range (len(targetWord)):\n",
    "            x3 += str(ord(targetWord[i]) - 97)\n",
    "        return int(x1) + int(x2) == int(x3)\n",
    "        # l1 = {\"a\":0, \"b\":1, \"c\":2, \"d\":3, \"e\":4, \"f\":5, \"g\":6, \"h\":7, \"i\":8, \"j\":9}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def num(x):\n",
    "            ans=''\n",
    "            for i in x:\n",
    "                ans+=str(ord(i)-ord('a'))\n",
    "            return int(ans)\n",
    "        return num(firstWord)+num(secondWord)==num(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def number(s):\n",
    "            l = [str(ord(c)-97) for c in s]\n",
    "            return int(''.join(l))\n",
    "        return number(firstWord) + number(secondWord) == number(targetWord)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        a = int(\"\".join([str(ord(c) - 97) for c in firstWord]))\n",
    "        b = int(\"\".join([str(ord(c) - 97) for c in secondWord]))\n",
    "        c = int(\"\".join([str(ord(c) - 97) for c in targetWord]))\n",
    "        return a + b == c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def f(w):\n",
    "            cnt = 10**(len(w)-1)\n",
    "            ans = 0\n",
    "            for c in w:\n",
    "                ans += (ord(c) - ord('a'))*cnt\n",
    "                cnt //= 10\n",
    "            return ans\n",
    "        return f(firstWord) + f(secondWord) == f(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        f, s, t = '', '', ''\n",
    "        for i in firstWord:\n",
    "            f += str(ord(i) - 97)\n",
    "        for j in secondWord:\n",
    "            s += str(ord(j) - 97)\n",
    "        for k in targetWord:\n",
    "            t += str(ord(k) - 97)\n",
    "        f, s, t = int(f), int(s), int(t)\n",
    "        if f + s == t:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        x1 = 0\n",
    "        x2 = 0\n",
    "        x3 = 0\n",
    "        for i in range (len(firstWord)):\n",
    "            x1 += (ord(firstWord[i]) - 97) * 10 ** (len(firstWord) - i)\n",
    "        for i in range (len(secondWord)):\n",
    "            x2 += (ord(secondWord[i]) - 97) * 10 ** (len(secondWord) - i) \n",
    "        for i in range (len(targetWord)):\n",
    "            x3 += (ord(targetWord[i]) - 97) * 10 ** (len(targetWord) - i) \n",
    "        return x1 + x2 == x3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def get_num(self,s:str):\n",
    "        ans=\"\"\n",
    "        for c in s:\n",
    "            ans+=str(ord(c)-ord('a'))\n",
    "        print('ans',ans)\n",
    "        return int(ans)\n",
    "\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        n1=self.get_num(firstWord)\n",
    "        n2=self.get_num(secondWord)\n",
    "        n3=self.get_num(targetWord)\n",
    "        return n1+n2==n3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def str_num(s):\n",
    "            n=len(s)\n",
    "            res=0\n",
    "            for i in range(n-1,-1,-1):\n",
    "                res+=(ord(s[i])-ord(\"a\"))*10**(n-1-i)\n",
    "            return res\n",
    "\n",
    "\n",
    "        if str_num(firstWord)+str_num(secondWord)==str_num(targetWord):\n",
    "            return True\n",
    "        return False\n",
    "    \n",
    "    \n",
    "\n",
    "            \n",
    "            \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def decode(word: str) -> int:\n",
    "            res = 0\n",
    "            for ch in word:\n",
    "                res *= 10\n",
    "                res += ord(ch) - ord('a')\n",
    "            return res\n",
    "        \n",
    "        return decode(firstWord) + decode(secondWord) == decode(targetWord)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        letters_to_integers = {chr(i): str(i - ord('a')) for i in range(ord('a'), ord('z') + 1)}\n",
    "        #firstWord_count = int(letters_to_integers[firstWord])\n",
    "        firstWord_count = ''\n",
    "        secondWord_count = ''\n",
    "        targetWord_count = ''\n",
    "        for ch in firstWord:\n",
    "            firstWord_count = firstWord_count + letters_to_integers[ch]\n",
    "        firstWord_count = int(firstWord_count)\n",
    "\n",
    "        for ch in secondWord:\n",
    "            secondWord_count += letters_to_integers[ch]\n",
    "        secondWord_count = int(secondWord_count)\n",
    "\n",
    "        for ch in targetWord:\n",
    "            targetWord_count += letters_to_integers[ch]\n",
    "        targetWord_count = int(targetWord_count)\n",
    "\n",
    "        return firstWord_count + secondWord_count == targetWord_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        firstWord = list(firstWord)\n",
    "        for i in range(len(firstWord)):\n",
    "            firstWord[i] = str(ord(firstWord[i]) - ord('a'))\n",
    "        firstWord = int(''.join(firstWord))\n",
    "        \n",
    "        secondWord = list(secondWord)\n",
    "        for i in range(len(secondWord)):\n",
    "            secondWord[i] = str(ord(secondWord[i]) - ord('a'))\n",
    "        secondWord = int(''.join(secondWord))\n",
    "\n",
    "        targetWord = list(targetWord)\n",
    "        for i in range(len(targetWord)):\n",
    "            targetWord[i] = str(ord(targetWord[i]) - ord('a'))\n",
    "        targetWord = int(''.join(targetWord))\n",
    "\n",
    "        if firstWord + secondWord == targetWord:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        first=''\n",
    "        second=''\n",
    "        target=''\n",
    "        for i in firstWord:\n",
    "            first+=str(ord(i)-ord('a'))\n",
    "        for i in secondWord:\n",
    "            second+=str(ord(i)-ord('a'))\n",
    "        for i in targetWord:\n",
    "            target+=str(ord(i)-ord('a'))\n",
    "        if int(first)+int(second)==int(target):\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        idx=ord('a')\n",
    "        f=''\n",
    "        for i in range(len(firstWord)):\n",
    "            f+=str(ord(firstWord[i])-idx)\n",
    "        s=''\n",
    "        for i in range(len(secondWord)):\n",
    "            s+=str(ord(secondWord[i])-idx)\n",
    "        t=''\n",
    "        for i in range(len(targetWord)):\n",
    "            t+=str(ord(targetWord[i])-idx)\n",
    "        if int(f)+int(s)==int(t):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def get_num(word):\n",
    "    num = 0\n",
    "    lengh = len(word)\n",
    "    for i in range(lengh):\n",
    "        num += (ord(word[i]) - 97) * 10 **(lengh-i-1)\n",
    "    return num\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        return get_num(firstWord) + get_num(secondWord) == get_num(targetWord)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        # 字母  --> 数字转换函数\n",
    "        def tranformer(s):\n",
    "            tm = \"\"\n",
    "            for ch in s:\n",
    "                tm += str(ord(ch)-97)\n",
    "            return int(tm)\n",
    "\n",
    "        return tranformer(firstWord)+tranformer(secondWord) == tranformer(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        cur=0\n",
    "        for ind,iii in enumerate([firstWord,secondWord,targetWord]):\n",
    "            val=int(\"\".join([str(ord(i)-ord(\"a\")) for i in iii]))\n",
    "            cur+=val if ind<2 else -val\n",
    "        return cur==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        n1=len(firstWord)\n",
    "        n2=len(secondWord)\n",
    "        n3=len(targetWord)\n",
    "        firstnum=''\n",
    "        secondnum=''\n",
    "        thirdnum=''\n",
    "        for i in range(n1):\n",
    "            firstnum+=str(ord(firstWord[i])-ord('a'))\n",
    "        for i in range(n2):\n",
    "            secondnum+=str(ord(secondWord[i])-ord('a'))\n",
    "        for i in range(n3):\n",
    "            thirdnum+=str(ord(targetWord[i])-ord('a'))\n",
    "        return (int(firstnum)+int(secondnum)==int(thirdnum))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        ans1,ans2,ans3=0,0,0\n",
    "        n1,n2,n3=len(firstWord),len(secondWord),len(targetWord)\n",
    "        for i in range(n1):\n",
    "            ans1=ans1*10+(ord(firstWord[i])-97)\n",
    "        for i in range(n2):\n",
    "            ans2=ans2*10+(ord(secondWord[i])-97)\n",
    "        for i in range(n3):\n",
    "            ans3=ans3*10+(ord(targetWord[i])-97)\n",
    "        return ans1+ans2==ans3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def fun(x):\n",
    "            res = ''\n",
    "            for i in x:\n",
    "                res += str(ord(i)-97)\n",
    "            return int(res)\n",
    "        return fun(firstWord) + fun(secondWord) == fun(targetWord)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        a=[]\n",
    "        b=[]\n",
    "        c=[]\n",
    "        for i in firstWord:\n",
    "            a.append(str(ord(i)-ord('a')))\n",
    "        for i in secondWord:\n",
    "            b.append(str(ord(i)-ord('a')))\n",
    "        for i in targetWord:\n",
    "            c.append(str(ord(i)-ord('a')))\n",
    "        a=''.join(a)\n",
    "        b=''.join(b)\n",
    "        c=''.join(c)\n",
    "        return int(a)+int(b)==int(c)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        value1, value2, value3 = 0, 0, 0\n",
    "        for ch in firstWord:\n",
    "            value1 = value1 * 10 + ord(ch) - ord('a')\n",
    "        for ch in secondWord:\n",
    "            value2 = value2 * 10 + ord(ch) - ord('a')\n",
    "        for ch in targetWord:\n",
    "            value3 = value3 * 10 + ord(ch) - ord('a')\n",
    "        return value1 + value2 == value3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        firstnum = 0\n",
    "        secondnum = 0\n",
    "        resnum = 0\n",
    "        for i in range(len(firstWord)-1, -1, -1):\n",
    "            firstnum+=(10**(len(firstWord)-1-i))*(ord(firstWord[i])-97)\n",
    "        print(firstnum)\n",
    "        for j in range(len(secondWord)-1, -1, -1):\n",
    "            secondnum+=(10**(len(secondWord)-1-j))*(ord(secondWord[j])-97)\n",
    "        print(secondnum)\n",
    "        for k in range(len(targetWord)-1, -1, -1):\n",
    "            resnum+=(10**(len(targetWord)-1-k))*(ord(targetWord[k])-97)\n",
    "        print(resnum)\n",
    "        res = firstnum+secondnum\n",
    "        if res ==resnum:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:\n",
    "        def decode(word: str) -> int:\n",
    "            res = 0\n",
    "            for ch in word:\n",
    "                res *= 10\n",
    "                res += ord(ch) - ord('a')\n",
    "            return res\n",
    "        \n",
    "        return decode(firstWord) + decode(secondWord) == decode(targetWord)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
